#include <inifilerd/IniFileReader.h>

class Handler : public IniFile::Handler
{
    const char *tokenName(int token)
    {
        static const char *namedToken[] = {
            "string",
            "non quoted string",
            "separator",
            "comment starter",
            "line terminator",
            "end of file",
            "unknown"
        };
        static char singleChar[2] = "?";
        if (token < 256) {
            singleChar[0] = static_cast<char>(token);
            return singleChar;
        } else
            return namedToken[token - 256];
    }
	virtual bool onError(unsigned long line, unsigned int column,
                         IniFile::ErrorID errorno, int token)
	{
	    std::cout << "Error on line " << line << " at column " << column << ": ";
	    switch (errorno) {
        case IniFile::ERROR_LEXER_UNTERMINATED_STRING:
            std::cout << "unterminated string." << std::endl;
            break;
        case IniFile::ERROR_SYNTAX_WRONG_TOKEN:
            std::cout << "expected '" << tokenName(token)
                      << "'."<< std::endl;
            break;
        case IniFile::ERROR_SYNTAX_STATEMENT_EXPECTED:
            std::cout << "statement expected." << std::endl;
            break;
        case IniFile::ERROR_SYNTAX_STATEMENT_TERMINATOR_EXPECTED:
            std::cout << "statement terminator expected." << std::endl;
            break;
        case IniFile::ERROR_SYNTAX_NAME_EXPECTED:
            std::cout << "name expected." << std::endl;
            break;
        case IniFile::ERROR_SYNTAX_SEPARATOR_EXPECTED:
            std::cout << "separator expected." << std::endl;
            break;
        case IniFile::ERROR_SYNTAX_VALUE_EXPECTED:
            std::cout << "value expected." << std::endl;
            break;
	    }
	    return true;
	}
	virtual void onSection(const std::string &name)
	{
	    std::cout << '[' << name << ']' << std::endl;
	}
	virtual void onProperty(const std::string &name, const std::string &value)
	{
	    std::cout << name << '=' << value << std::endl;
	}
};

int main()
{
    Handler handler;
    IniFile::Reader reader(&handler);
    reader.open("test.ini");
    reader.parse();
    return 0;
}
